Jetfire Code: Hints for Writing Good Code

Modified on 2009/12/07 02:04 by Charles — Categorized as: Jetfire Code, Jetfire Language

Table of Contents [Hide/Show]


Jetfire Code: Hints for Writing Good Code

This page contains a number of suggestions that may help in writing good Jetfire code. The suggestions include:

Structure Hints




// TheNameOfTheWorkflow    W O R K F L O W
//===================================================================================
// TheNameOfTheFile.txt
//===================================================================================
// Copyright (C) 2009 TrackerRealm Corporation
// This file is part of Jetfire.  http://Jetfire.ca
// 
// Jetfire is open software: you can redistribute it and/or modify it under the terms of the 
// GNU General Public License as published by the Free Software Foundation, version 3 of the License.
// 
// Jetfire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
// See the GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License along with Jetfire.  
// If not, see http://www.gnu.org/licenses.
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT.
//===================================================================================
// DisplayName: 'Friendly name for the class'
// This code does the following:
// * List of features 

namespace TheNamespace
{
	// This workflow provides a Base Class for associating Questions and Answers.
	public workflow TheNameOfTheWorkflow
	{
	}
}




   // A list property in the parent workflow.
   public List WorkflowList
   {
      get;
      private set;
   }
   // Create a workflow and return it to the calling method.
   public MyWorkflow AddMyWorkflow()
   {
      // Create a workflow.
      MyWorkflow w = new MyWorkflow();
      // the new workflow is added to a list in the parent workflow to create a reference.
      WorkflowList.Add(w);
      // the new workflow is returned so that the calling method can use it directly.
      return w;
   }

Syntax Hints



   // SomeProperty stores something.
   // Note that this property can be read and written by anyone.
   public string SomeProperty
   {
      get;
      set;
   }


   // SomeProperty stores something.
   // The states access modifier is added before the access access modifier.
   public string SomeProperty : states(SomeState), access("SomeRole")
   {
      get;
      set;
   }

Semantic Hints


   // Store the Last time that the workflow was updated.
   // Note the use of the private access modifier.  This property can only be set from within the workflow
   public DateTime LastUpdated
   {
      get;
      private set;
   }


   // Add the name of this method to the 'Save Method' Edit Property of the Jetfire Web Part.
   public void FinishEdit()
   {
      // Update the Last time that the workflow was saved when the Workflow is saved.
      LastUpdate = DateTime.Now;
   }

   // Check if the first and last variables are blank when the workflow is saved.
   public void FinishEdit()
   {
      if (first == "")
         throw exception("Enter First Name");
      if (last == "")
         throw exception("Enter Last Name");
   }



Convention a) prefix methods with 'Promote_to_'
   public Delete() { }
   public void Promote_to_Delete()
   {
      enterstate Delete();
   }

Convention b) use present tense for methods
   public Deleted() { }
   public void Delete()
   {
      enterstate Deleted();
   }


   public string MyFavoriteProperty
   {
	get;
	set : access(IsNotGuest);
   }
   public bool IsNotGuest()
   {
        return User.Login.Name != "Guest";
   }